<template>
  <view class="empty-data" :style="containerStyle">
    <view class="empty-icon" :style="iconStyle">
      <image
        v-if="icon"
        :src="icon"
        :style="{ width: iconSize + 'rpx', height: iconSize + 'rpx' }"
        mode="aspectFit"
      />
      <text v-else class="default-icon">📭</text>
    </view>

    <view class="empty-text" :style="textStyle">
      <text class="main-text">{{ mainText }}</text>
      <text v-if="subText" class="sub-text">{{ subText }}</text>
    </view>

    <view v-if="showButton" class="empty-button">
      <button
        class="action-btn"
        :style="buttonStyle"
        @click="handleButtonClick"
      >
        {{ buttonText }}
      </button>
    </view>
  </view>
</template>

<script>
export default {
  name: "EmptyData",
  props: {
    // 图标路径
    icon: {
      type: String,
      default: "",
    },
    // 图标大小（rpx）
    iconSize: {
      type: Number,
      default: 120,
    },
    // 主要文字
    mainText: {
      type: String,
      default: "暂无数据",
    },
    // 次要文字
    subText: {
      type: String,
      default: "",
    },
    // 是否显示按钮
    showButton: {
      type: Boolean,
      default: false,
    },
    // 按钮文字
    buttonText: {
      type: String,
      default: "去添加",
    },
    // 容器样式
    containerStyle: {
      type: Object,
      default: () => ({}),
    },
    // 图标样式
    iconStyle: {
      type: Object,
      default: () => ({}),
    },
    // 文字样式
    textStyle: {
      type: Object,
      default: () => ({}),
    },
    // 按钮样式
    buttonStyle: {
      type: Object,
      default: () => ({}),
    },
  },
  methods: {
    handleButtonClick() {
      this.$emit("button-click");
    },
  },
};
</script>

<style lang="scss" scoped>
.empty-data {
  width: 100vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60rpx 0;
  min-height: 400rpx;

  .empty-icon {
    margin-bottom: 30rpx;
    display: flex;
    align-items: center;
    justify-content: center;

    .default-icon {
      font-size: 120rpx;
      color: #c0c4cc;
    }
  }

  .empty-text {
    display: flex;
    text-align: center;
    flex-direction: column;
    margin-bottom: 40rpx;

    .main-text {
      display: block;
      font-size: 32rpx;
      color: #606266;
      margin-bottom: 16rpx;
      font-weight: 500;
    }

    .sub-text {
      display: block;
      font-size: 28rpx;
      color: #909399;
      line-height: 1.5;
    }
  }

  .empty-button {
    .action-btn {
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      color: #fff;
      border: none;
      border-radius: 50rpx;
      padding: 20rpx 60rpx;
      font-size: 28rpx;
      font-weight: 500;
      box-shadow: 0 8rpx 20rpx rgba(102, 126, 234, 0.3);
      transition: all 0.3s ease;

      &:active {
        transform: translateY(2rpx);
        box-shadow: 0 4rpx 10rpx rgba(102, 126, 234, 0.3);
      }
    }
  }
}

// 深色主题样式
.empty-data.dark {
  .empty-text {
    .main-text {
      color: #e5eaf3;
    }

    .sub-text {
      color: #a3a6ad;
    }
  }

  .empty-icon .default-icon {
    color: #4c4d4f;
  }
}

// 小尺寸样式
.empty-data.small {
  min-height: 300rpx;
  padding: 40rpx 30rpx;

  .empty-icon {
    margin-bottom: 20rpx;

    .default-icon {
      font-size: 80rpx;
    }
  }

  .empty-text {
    margin-bottom: 30rpx;

    .main-text {
      font-size: 28rpx;
    }

    .sub-text {
      font-size: 24rpx;
    }
  }
}
</style>
